var app=angular.module("myApp",['ngRoute'],routes);
			function routes($routeProvider){
				$routeProvider			
					.when("/",{templateUrl:"./indexs.html"})
					.when("/goods",{templateUrl:"./goods.html"})
					.when("/car",{templateUrl:"./car.html"})
					.when("/xq_page",{templateUrl:"./xq_page.html"})
					.when("/reg",{templateUrl:"./reg.html"})
					.when("/login",{templateUrl:"./login.html"})
			}
			app.controller("cont",function($scope,$http){
				$scope.time=new Date();
				$http.get("./php/index.php").success(function(msg){
					$scope.data=msg;
					angular.forEach($scope.data,function(val){
						val.num=0;
					});
				});
				$scope.car=[];
				$scope.item1=[];
				$scope.addCar=function(goods,bool){
					angular.forEach($scope.data,function(val,index){
					if(goods==val.gid){
						if(val.num==0){
							val.num=1;
							setIco(event,val.img);
							$scope.car.push($scope.data[index]);
						}else{
							val.num++;
							setIco(event,val.img);
						}
					}
					
					});
				}
				$scope.item2=[];
				$scope.addCar1=function(goods){
					angular.forEach($scope.data,function(val,index){
						if(goods==val.gid){
								$scope.item1.push($scope.data[index]);
								$scope.item2=$scope.item1;
								if($scope.item1.length>=2){
									$scope.item2.splice(0,1);
								}
							console.log(val);
						}
					});
				}
				$scope.xq_add=function(boos){
					console.log(boos);
					angular.forEach($scope.item2,function(val,index){
							if(boos){
								if(val.num==0){
									val.num=1;
									$scope.car.push(val);
								}else{
									val.num++;
								}
									
							}
					});
				}
				var fol=true;	
				$scope.dj_bj=function(){
					if(fol){
						$(".delees").stop().animate({"right":0},100);
						$scope.dele_g=repeats;
						fol=false;
					}else{
						$(".delees").stop().animate({"right":-34},100);
						fol=true;	
					}
					
				}
				
				$scope.dele_g=repeats;
				function repeats(goods1){
						angular.forEach($scope.car,function(val,index){
							if(goods1==val.gid){
								if(val.bool){
									$scope.car.splice(index,1);
									val.num=0;
								}else{
									var warn=confirm("亲，没选中不能删除哦！");	
								}
							}
						});
				}
				$scope.demo=function(gids,solve){
					angular.forEach($scope.car,function(val,index){
						if(gids==val.gid){
							if(solve){
								$(".delees").eq(index).stop().animate({"right":0},100);
							}else{
								$(".delees").eq(index).stop().animate({"right":-34},100);
							}
						}
					});
				}
				$("#all_cge").click(function(){
					console.log(123);
				});
				$scope.userLogin=function(){
					var userName=document.getElementById("txtUserName_login");
					var userPsw=document.getElementById("txtLoginPwd_login");
				      	var xmlhttp=new XMLHttpRequest();//创建请求对象
				      	
				      	xmlhttp.onreadystatechange=function(){
						        if(xmlhttp.readyState==4&&xmlhttp.status==200){
						        	if(xmlhttp.responseText==12||xmlhttp.responseText==21){
										alert("登录成功");
										location.href="./index.html";
										return true;
						        	}else{
						        		alert("该用户名不存在，请重新输入！");
						        		return false;
						        	}
						        }
					        }
				      	xmlhttp.open("GET","./php/jd_login.php?uname="+userName.value+"&upwd="+userPsw.value,true);//初始化
					        xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
					        xmlhttp.send("uname="+userName.value+"&upwd="+userPsw.value);//发送
				
				}
				//监听
				$scope.$watch("car",function(){
					$scope.totals=0;
					$scope.t_num=0;
					angular.forEach($scope.car,function(val,index){
						$scope.t_num+=val.num;
						$scope.totals+=val.price*val.num*0.8;
					});
				},true);
				//检索
				$scope.ups=function(tfs){
					if(tfs){
						$scope.val="price*0.8";
					}else{
						$scope.val="-price*0.8";
					}
				}
				var bols=true;
				$scope.check=function(){
					if(bols){
						bols=false;
						$("#btn_s").stop().animate({"top":50},100);
						$("#cheng").stop().animate({"height":100},100);
						$(".t_serch").find("img").addClass("tiao_z").removeClass("tiao_z1");
					}else{
						bols=true;
						$("#btn_s").stop().animate({"top":0},100);
						$("#cheng").stop().animate({"height":50},100);
						$(".t_serch").find("img").addClass("tiao_z1").removeClass("tiao_z");
					}
				}
			});
		function setIco(event,dds) {

            // 变量区,当前按钮,当前图片
        
            var flyer = $('<img class="u-flyer" style="width:15%"; src="'+dds+'">');

            
            //鼠标在页面点击开始位置计算.
            var top = $(window).scrollTop();
            
            var dh = event.pageY;

            var newh = dh - top;


            // 鼠标结束位置计算 
            var oDiv = $('#end').offset();
            var newdh = oDiv.top - top;

            flyer.fly({
                start: {
                    left: event.pageX-$(".wrap").width()+75,
                    top: newh-80
                },
                end: {
                    left: oDiv.left,
                    top: newdh,
                    width: 0,
                    height: 0
                }
            });
       }